﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>查询礼品</title>

    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Scripts/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div>
        <script type="text/html" id="barDemo">
            <div class="layui-btn-container">
                <button type="button" lay-event="add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe654;新增</i></button>
                <button type="button" lay-event="update" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe642;修改</i></button>
                <button type="button" lay-event="delete" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe640;删除</i></button>
            </div>
        </script>
        <table class="layui-inline" lay-filter="table" id="cardList"></table>
    </div>
    
    <script>

        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;
            //载入表格
            table.render({
                elem: '#cardList',
                url: "/Present/PreBind",
                toolbar: '#barDemo',
                method: "post",
                //开启分页
                page: 'true',
                cols: [
                    [{
                        type: 'checkbox'
                    },  {
                        field: 'EG_ID',
                        width: 150,
                        title: '礼品编号',
                        sort: true
                    },
                    {
                        field: 'EG_GiftCode',
                        width: 150,
                        title: '礼品代号',
                        sort: true
                    },
                    {
                        field: 'EG_GiftName',
                        width: 150,
                        title: '礼品名称',

                    },
                    {
                        field: 'EG_Point',
                        width: 150,
                        title: '所需积分',
                        sort: true
                    },
                    {
                        field: 'EG_Number',
                        width: 150,
                        title: '礼品数量',
                        sort: true,
                    },
                    {
                        field: 'EG_ExchangNum',
                        width: 150,
                        title: '已兑换数量',
                        sort: true,
                    },
                    {
                        field: 'EG_Remark',
                        width: 150,
                        title: '备注',
                    }
                    ]
                ]
            });

           
             //头部工具栏
             table.on('toolbar(table)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id).data;
              switch(obj.event){
                case 'add':
                layer.open({
                    type: 2,
                    content: ['/Present/PreInsert', 'no'],
                    area: ['500px', '560px'],
                    offset: ['100px', '400px'],
                    skin: 'layui-layer-molv',
                    maxmin: true,
                    id: 'add',
                    end: function () { table.reload('cardList') }
                });
                break;
                  case 'delete':
                 if (checkStatus[0] != null) {
                            var EG_ID = checkStatus[0].EG_ID;
                            layer.confirm('您确定要删除编号为' + EG_ID + "的礼品吗", function (index) {
                                $.ajax({
                                    type: "post",
                                    url: "/Present/PreDele",
                                    data: { EG_ID: EG_ID },
                                    success: function (data) {
                                        if (data.code == 0) {
                                            parent.layer.msg(data.msg, { icon: 1 });
                                            table.reload('cardList');
                                            obj.config.U_ID.del();
                                        } else {
                                            parent.layer.msg(data.msg, { icon: 5 });
                                        }
                                    }
                                })
                                layer.close(index);
                            });
                        } else {
                            layer.msg("请选择一行数据", { icon: 7 });
                        }
                    
                break;
                  case 'update':
                      if (checkStatus[0] != null) {
                          var EG_ID = checkStatus[0].EG_ID;
                                layer.open({
                                    type: 2,
                                    content: ['/Present/PreUpdate/' + EG_ID + '', 'no'],
                                    area: ['500px', '560px'],
                                    offset: ['100px', '400px'],
                                    skin: 'layui-layer-molv',
                                    maxmin: true,
                                    //弹窗关闭刷新列表
                                    end: function () { table.reload('cardList') }
                                });

                        } else {
                               layer.msg("请选择一行数据", { icon: 7 });
                        }
                break;
              };
            });
           

        })



    </script>
</body>
</html>
